$(function() {
	
	staticMaps();
	
	// chartOne();
	chartFour();
	// chartTwo();
})


/**
 * 查询费用排行，并存入全局对象
 */
function staticMaps(){
	$.ajax({
		url: 'http://localhost:9000/statistical/freightrank/moneyfreight',
		type: 'get',
		dataType: 'json',
		success: function(map) {
			staticMaps=map;
			
			totalFreights = staticMaps.totalFreights;
			
			names = new Array(); //姓名
			reduceFunds = new Array();    //减款
			payKickbacks = new Array();    //付回扣
			moneyOfChangePays = new Array();    //代收货款变更后金额
			carryGoodsFees = new Array();    //送货费
			carriages = new Array();    //运费
			insurances = new Array();    //保险费
			
			for (var i = 0; i < totalFreights.length || i<5; i++) {
				var totalFreight = totalFreights[i];
				names.push(totalFreight.name);					//姓名
				reduceFunds.push(totalFreight.reduceFund);    //减款
				payKickbacks.push(totalFreight.payKickback);   //付回扣
				moneyOfChangePays.push(totalFreight.moneyOfChangePay);    //代收货款变更后金额
				carryGoodsFees.push(totalFreight.carryGoodsFee);    //送货费
				carriages.push(totalFreight.carriage);    //运费
				insurances.push(totalFreight.insurance);  //保险费
			}
			// chartFour();
		}
	})
}
/**
 * @param {Object} map
 * 图表结构
 */
function chartOne() {
	// 基于准备好的dom，初始化echarts实例
	var myChart = echarts.init(document.getElementById('main'));
	// app.title = '堆叠柱状图';
	option = {
	    tooltip : {
	        trigger: 'axis',
	        axisPointer : {            // 坐标轴指示器，坐标轴触发有效
	            type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
	        }
	    },
	    legend: {
	        data:['罚款','押金扣除','营外1','营外2','营外3']
	    },
	    grid: {
	        left: '3%',
	        right: '4%',
	        bottom: '3%',
	        containLabel: true
	    },
	    xAxis : [
	        {
	            type : 'category',
				// data : names
	            data : ['一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月']
	        }
	    ],
	    yAxis : [
	        {
	            type : 'value'
	        }
	    ],
	    series : [
	        {
	            name:'罚款',
	            type:'bar',
				// data : reduceFunds
	            data:[320, 332, 301, 334, 390,320, 332, 301, 334, 390,443,445]
	        },
	        {
	            name:'押金扣除',
	            type:'bar',
	            // stack: '广告',
	            // data:payKickbacks
				 data:[320, 332, 301, 334, 390,320, 332, 301, 334, 390,443,445]
	        },
	        {
	            name:'营外1',
	            type:'bar',
	            // stack: '广告',
	            // data:moneyOfChangePay,
				 data:[30, 332, 01, 334, 390,320, 332, 301, 334, 390,443,445]
	        },
	        {
	            name:'营外2',
	            type:'bar',
	            // stack: '广告',
	            // data:carryGoodsFees
				 data:[320, 33, 301, 34, 390,320, 332, 301, 334, 390,443,445]
	        },
	        {
	            name:'营外3',
	            type:'bar',
	            // data:carriage
				 data:[320, 32, 301, 34, 390,320, 332, 301, 334, 390,443,445]
	        }
	    ]
	};


	// 使用刚指定的配置项和数据显示图表。
	myChart.setOption(option);
}


/**
 * 
 */
function chartFour() {
	// 基于准备好的dom，初始化echarts实例
	var myChart = echarts.init(document.getElementById('main'));
	
	option = {
	    title : {
	        text: '营业外收入',
	        subtext: '纯属虚构'
	    },
	    tooltip : {
	        trigger: 'axis'
	    },
	    legend: {
	        data:['罚款','押金扣除','营外1','营外2','营外3']
	    },
	    toolbox: {
	        show : true,
	        feature : {
	            dataView : {show: false, readOnly: false},
	            magicType : {show: true, type: ['line', 'bar']},
	            restore : {show: true},
	            saveAsImage : {show: true}
	        }
	    },
	    calculable : true,
	    xAxis : [
	        {
	            type : 'category',
	            data : ['1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月']
	        }
	    ],
	    yAxis : [
	        {
	            type : 'value'
	        }
	    ],
	    series : [
	        {
	            name:'罚款',
	            type:'bar',
	            data:[2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3],
	            markPoint : {
	                data : [
	                    {type : 'max', name: '最大值'},
	                    {type : 'min', name: '最小值'}
	                ]
	            },
	            markLine : {
	                data : [
	                    {type : 'average', name: '平均值'}
	                ]
	            }
	        },
	        {
	            name:'押金扣除',
	            type:'bar',
	            data:[2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3],
	            markPoint : {
	                data : [
	                    {name : '年最高', value : 182.2, xAxis: 7, yAxis: 183},
	                    {name : '年最低', value : 2.3, xAxis: 11, yAxis: 3}
	                ]
	            },
	            markLine : {
	                data : [
	                    {type : 'average', name : '平均值'}
	                ]
	            }
	        },
	        {
	            name:'营外1',
	            type:'bar',
	            data:[2.6, 5.9, 9.0, 23.4, 22.7, 70.7, 135.6, 182.2, 48.7, 18.8, 6.0, 2.3],
	            markPoint : {
	                data : [
	                    {name : '年最高', value : 182.2, xAxis: 7, yAxis: 183},
	                    {name : '年最低', value : 2.3, xAxis: 11, yAxis: 3}
	                ]
	            },
	            markLine : {
	                data : [
	                    {type : 'average', name : '平均值'}
	                ]
	            }
	        },
	        {
	            name:'营外2',
	            type:'bar',
	            data:[2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 172.6, 182.2, 48.7, 18.8, 6.0, 2.3],
	            markPoint : {
	                data : [
	                    {name : '年最高', value : 182.2, xAxis: 7, yAxis: 183},
	                    {name : '年最低', value : 2.3, xAxis: 11, yAxis: 3}
	                ]
	            },
	            markLine : {
	                data : [
	                    {type : 'average', name : '平均值'}
	                ]
	            }
	        },
	        {
	            name:'营外3',
	            type:'bar',
	            data:[2.6, 5.9, 9.0, 26.4, 222.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3],
	            markPoint : {
	                data : [
	                    {name : '年最高', value : 182.2, xAxis: 7, yAxis: 183},
	                    {name : '年最低', value : 2.3, xAxis: 11, yAxis: 3}
	                ]
	            },
	            markLine : {
	                data : [
	                    {type : 'average', name : '平均值'}
	                ]
	            }
	        }
	    ]
	};
	// 使用刚指定的配置项和数据显示图表。
	myChart.setOption(option);
}